<?php

namespace app\forms\user;


use app\forms\Model;
use app\models\User;
use app\components\helpers\MappingHelper;
use app\components\validators\PositiveInteger;

class StatusForm extends Model
{
    public $userId;
    public $status;

    public function rules()
    {
        return [
            ['userId', 'required'],
            ['userId', 'each', 'rule' => [PositiveInteger::class]],
            ['status', 'integer'],
            ['status', 'in', 'range' => array_column(MappingHelper::statusList(), 'id')]
        ];
    }

    public function setUserStatus()
    {
        User::updateAll(['status' => $this->status], ['in', 'id', $this->userId]);
    }
}